<template>
	<view class="wrap" style="background-color: #fefdfe;">
		<u-sticky>
			<view style="background-color: white;border-bottom: 1px solid white;padding-top: 5px;">
				<u-steps :current="currentPage" activeColor='green'>
					<u-steps-item title="客户信息"></u-steps-item>
					<u-steps-item title="订单信息"></u-steps-item>
					<u-steps-item title="提交订单"></u-steps-item>
				</u-steps>
			</view>
		</u-sticky>
		<view style="padding: 15px;">
			<up-back-top :scroll-top="scrollTop" top="300" mode="circle" bottom="250rpx"
				:iconStyle="{'fontSize': '32rpx','color': '#ffffff'}" :customStyle="{'backgroundColor': 'green'}"
				class="kkasd"></up-back-top>
			<up-form v-show="currentPage==0" class="apply-form-field" ref="orderForm" :model="form" labelPosition="left"
				:labelStyle="labelStyle" :borderBottom="true">
				<!-- #ifdef APP-->
				<up-form-item label="下单日期" label-width="120" prop="orderDate" required :borderBottom="true"
					@tap="orderDateClick()">
					<up-input placeholder="请选择下单日期" type="text" class="form-field-select" v-model="form.orderDate"
						border="none" readonly disabled />
				</up-form-item>
				<!-- #endif -->
				<!-- #ifdef H5-->
				<up-form-item label="下单日期" label-width="120" prop="orderDate" required :borderBottom="true">
					<up-input placeholder="请选择下单日期" type="text" class="form-field-select"
						@click.native="orderDateShow=true" v-model="form.orderDate" border="none" @focus='blur'
						disabled />
				</up-form-item>
				<!-- #endif -->
				<up-form-item label="销售类型" label-width="120" prop="sample" required :borderBottom="true">
					<up-radio-group v-model="form.sample" shape="square" disabled>
						<up-radio v-for="(item, index) in saleTypeList" :key="index" :name="item" :label="item"
							:customStyle="{marginRight: '0px'}" activeColor="green">
						</up-radio>
					</up-radio-group>
				</up-form-item>
				<up-form-item label="发货方式" label-width="120" prop="choiceCar" required :borderBottom="true">
					<up-radio-group v-model="form.choiceCar" shape="square" disabled>
						<up-radio v-for="(item, index) in choiceCarList" :key="index" :name="item" :label="item"
							:customStyle="{marginRight: '0px'}" activeColor="green">
						</up-radio>
					</up-radio-group>
				</up-form-item>
				<!-- #ifdef APP-->
				<up-form-item label="发货日期" label-width="120" prop="pickDate" required :borderBottom="true"
					@tap="pickDateClick">
					<up-input placeholder="请选择发货日期" type="text" class="form-field-select" v-model="form.pickDate"
						border="none" readonly disabled />
				</up-form-item>
				<up-form-item label="部门" label-width="120" prop="department" required :borderBottom="true"
					@tap='departmentClick'>
					<up-input placeholder="请选择部门" type="text" class="form-field-select" v-model="form.department"
						border="none" readonly disabled />
				</up-form-item>
				<up-form-item label="客户名称" label-width="120" prop="customerName" required :borderBottom="true"
					@tap='customerClick'>
					<up-input placeholder="请选择客户" type="text" class="form-field-select" v-model="form.customerName"
						border="none" readonly disabled />
				</up-form-item>
				<!-- #endif -->
				<!-- #ifdef H5-->
				<up-form-item label="发货日期" label-width="120" prop="pickDate" required :borderBottom="true">
					<up-input placeholder="请选择发货日期" type="text" class="form-field-select"
						@click.native="pickDateShow = true" v-model="form.pickDate" border="none" @focus='blur'
						disabled />
				</up-form-item>
				<up-form-item label="部门" label-width="120" prop="department" required :borderBottom="true">
					<up-input placeholder="请选择部门" type="text" class="form-field-select" v-model="form.department"
						@click.native='departmentShow=true' border="none" disabled />
				</up-form-item>
				<up-form-item label="客户名称" label-width="120" prop="customerName" required :borderBottom="true">
					<up-input placeholder="请选择客户" type="text" class="form-field-select" v-model="form.customerName"
						@click.native='customerShowClick' border="none" disabled />
				</up-form-item>
				<!-- #endif -->
				<up-form-item label="付款账期" label-width="120" prop="accountPeriod" required :borderBottom="true">
					<up-radio-group v-model="form.accountPeriod" shape="square" disabled>
						<up-radio v-for="(item, index) in accountPeriodList" :key="index" :name="item" :label="item"
							activeColor="green"></up-radio>
					</up-radio-group>
				</up-form-item>
				<up-form-item label="销售人员" label-width="120" prop="salesPerson" required :borderBottom="true">
					<up-input placeholder="请填写销售人员" type="text" class="form-field-select" v-model="form.salesPerson"
						border="none" disabled />
				</up-form-item>
				<up-form-item label="所在区域" label-width="120" prop="area" required :borderBottom="true">
					<up-radio-group v-model="form.area" shape="square" disabled>
						<up-radio v-for="(item, index) in areList" :key="index" :name="item" :label="item"
							activeColor="green"></up-radio>
					</up-radio-group>
				</up-form-item>
				<up-form-item label="收货人" label-width="120" prop="customerTake" required :borderBottom="true">
					<up-input placeholder="请填写收货人" type="text" class="form-field-select" v-model="form.customerTake"
						border="none" disabled />
				</up-form-item>
				<up-form-item label="收货人电话" label-width="120" prop="customerPhone" required :borderBottom="true">
					<up-input placeholder="请填写收货人电话" type="text" class="form-field-select" v-model="form.customerPhone"
						border="none" disabled />
				</up-form-item>
				<up-form-item label="收货人地址" label-width="120" prop="pcaAddress" required :borderBottom="true">
					<up-input placeholder="请填写收货人地址" type="text" class="form-field-select" v-model="form.pcaAddress"
						@click.native="cityShow=true" border="none" disabled />
				</up-form-item>
				<up-form-item label="收货人详细地址" label-width="120" prop="customerAddress" required :borderBottom="true">
					<up-input placeholder="请填写收货人详细地址" type="text" class="form-field-select"
						v-model="form.customerAddress" border="none" disabled />
				</up-form-item>
				<up-form-item label="客户形式" label-width="120" prop="customerForm" required :borderBottom="true">
					<up-input placeholder="请填写客户形式" type="text" class="form-field-select" v-model="form.customerForm"
						border="none" disabled />
				</up-form-item>
				<up-form-item label="客户付款方式" label-width="120" prop="customerPay" required :borderBottom="true">
					<up-radio-group v-model="form.customerPay" shape="square" disabled>
						<up-radio v-for="(item, index) in customerPayList" :key="index" :name="item" :label="item"
							activeColor="green"></up-radio>
					</up-radio-group>
				</up-form-item>
				<up-form-item label="客户付款账号" label-width="120" prop="customerAccount" required :borderBottom="true">
					<up-input placeholder="请填写客户付款账号" type="text" class="form-field-select"
						v-model="form.customerAccount" border="none" disabled />
				</up-form-item>
				<up-form-item label="是否开票" label-width="120" prop="isInvoicing" required :borderBottom="true">
					<up-radio-group v-model="form.isInvoicing" shape="square" disabled>
						<up-radio :key="0" :name="1" label="是" :customStyle="{marginRight: '16px'}"
							activeColor="green" />
						<up-radio :key="1" :name="0" label="否" :customStyle="{marginRight: '16px'}"
							activeColor="green" />
					</up-radio-group>
				</up-form-item>
				<up-form-item label="是否押车" label-width="120" prop="isUnloading" required :borderBottom="true">
					<up-radio-group v-model="form.isUnloading" shape="square" disabled>
						<up-radio :key="0" :name="1" label="是" :customStyle="{marginRight: '16px'}"
							activeColor="green" />
						<up-radio :key="1" :name="0" label="否" :customStyle="{marginRight: '16px'}"
							activeColor="green" />
					</up-radio-group>
				</up-form-item>
				<up-form-item label="押车天数" label-width="120" prop="unloadingDays" :required="form.isUnloading == 1"
					:borderBottom="true">
					<up-input placeholder="请填写押车天数" type="number" class="form-field-select"
						:disabled="form.isUnloading == 0" v-model="form.unloadingDays" border="none" disabled />
				</up-form-item>
				<up-form-item label="预计押车费用" label-width="120" prop="unloadingFare" :required="form.isUnloading == 1"
					:borderBottom="true">
					<up-input placeholder="请填写预计押车费用" type="number" class="form-field-select"
						:disabled="form.isUnloading == 0" v-model="form.unloadingFare" border="none" disabled />
				</up-form-item>
				<up-form-item label="是否加急" label-width="120" prop="isUrgent" required :borderBottom="true">
					<up-radio-group v-model="form.isUrgent" shape="square" disabled>
						<up-radio :key="0" :name="1" label="是" :customStyle="{marginRight: '16px'}"
							activeColor="green" />
						<up-radio :key="1" :name="0" label="否" :customStyle="{marginRight: '16px'}"
							activeColor="green" />
					</up-radio-group>
				</up-form-item>
				<up-form-item label="备注" label-width="120" :borderBottom="true">
					<up-input placeholder="请填写备注" type="textarea" class="form-field-select" v-model="form.remake"
						border="none" disabled />
				</up-form-item>
				<up-form-item label="相关图片" label-width="120" :borderBottom="true">
					<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
						:maxCount="10" disabled></u-upload>
				</up-form-item>
				<up-form-item label="相关文件" label-width="120" :borderBottom="true">
					<u-upload :fileList="fileList2" @afterRead="afterRead" @delete="deletePic" name="2" multiple
						:maxCount="10" disabled></u-upload>
				</up-form-item>
			</up-form>
			<up-form v-show="currentPage==1" class="apply-form-field" ref="orderSubForm" :model="orderSub"
				labelPosition="left">
				<up-tabs @click="tabsClick" :list="tabList" :current="orderSubCurrent" lineWidth="30" lineColor="green"
					:activeStyle="{
					            color: 'green',
					            fontWeight: 'bold',
					            transform: 'scale(1.05)'
					        }" :inactiveStyle="{
					            color: '#606266',
					            transform: 'scale(1)'
					        }" itemStyle="padding-left: 15px; padding-right: 15px; height: 44px;">
					<template #right style="padding-left: 4px;display: flex;">
						<u-icon name="plus-circle-fill" color="green" size="30" @click="addOrderSub"></u-icon>
					</template>
				</up-tabs>
				<u-line color="#00aa00" dashed></u-line>
				<!-- #ifdef APP-->
				<up-form-item label="产品" label-width="120" prop="productName" required :borderBottom="true"
					@tap="productNameClick()">
					<up-input placeholder="请选择产品" type="text" class="form-field-select" v-model="orderSub.productName"
						border="none" readonly :disabled="orderSub.disabled" />
				</up-form-item>
				<up-form-item label="SKU名称" label-width="120" prop="skuName" required :borderBottom="true"
					@tap="skuNameClick()">
					<up-input placeholder="请选择SKU名称" type="text" class="form-field-select" v-model="orderSub.skuName"
						border="none" readonly :disabled="orderSub.disabled" />
				</up-form-item>
				<!-- #endif -->
				<!-- #ifdef H5-->
				<up-form-item label="产品" label-width="120" prop="productName" required :borderBottom="true">
					<up-input placeholder="请选择产品" type="text" class="form-field-select" @click.native="productShow=true"
						v-model="orderSub.productName" border="none" @focus='blur' :disabled="orderSub.disabled" />
				</up-form-item>
				<up-form-item label="SKU名称" label-width="120" prop="skuName" required :borderBottom="true">
					<up-input placeholder="请选择SKU名称" type="text" class="form-field-select"
						@click.native="orderSub.params.skuShow=true" v-model="orderSub.skuName" border="none"
						@focus='blur' :disabled="orderSub.disabled" />
				</up-form-item>
				<!-- #endif -->
				<up-form-item label="外包装" label-width="120" prop="packageMethod" required :borderBottom="true">
					<up-radio-group v-if="orderSub.params.packageMethodList.length>0" v-model="orderSub.packageMethod"
						shape="square" :disabled="orderSub.disabled">
						<up-radio v-for="(item, index) in orderSub.params.packageMethodList" :key="item" :name="item"
							:label="item" activeColor="green"></up-radio>
					</up-radio-group>
					<up-input v-else placeholder="待SKU名称确认" type="text" class="form-field-select" readonly
						border="none" />
				</up-form-item>
				<up-form-item label="内包装" label-width="120" prop="innerPackageMethod"  :borderBottom="true">
					<up-radio-group v-if="orderSub.params.innerPackageMethodList.length>0"
						v-model="orderSub.innerPackageMethod" shape="square" :disabled="orderSub.disabled">
						<up-radio v-for="(item, index) in orderSub.params.innerPackageMethodList" :key="item"
							:name="item" :label="item" activeColor="green"></up-radio>
					</up-radio-group>
					<up-input v-else placeholder="待SKU名称确认" type="text" class="form-field-select" readonly
						border="none" />
				</up-form-item>
				<up-form-item label="品种" label-width="120" prop="varietyList" required :borderBottom="true">
					<u-checkbox-group v-if="orderSub.params.varietyNameList.length>0" v-model="orderSub.varietyList"
						placement="column" :disabled="orderSub.disabled">
						<u-checkbox :customStyle="{marginBottom: '8px'}"
							v-for="(item, index) in orderSub.params.varietyNameList" :key="item" :label="item"
							:name="item" activeColor="green">
						</u-checkbox>
					</u-checkbox-group>
					<up-input v-else placeholder="待SKU名称确认" type="text" class="form-field-select" readonly
						border="none" />
				</up-form-item>
				<up-form-item label="等级" label-width="120" prop="grade" required :borderBottom="true">
					<up-radio-group v-if="orderSub.params.gradeList.length>0" v-model="orderSub.grade" shape="square"
						:disabled="orderSub.disabled">
						<up-radio v-for="(item, index) in orderSub.params.gradeList" :key="item" :name="item"
							:label="item" activeColor="green"></up-radio>
					</up-radio-group>
					<up-input v-else placeholder="待SKU名称确认" type="text" class="form-field-select" readonly
						border="none" />
				</up-form-item>
				<up-form-item label="是否标重" label-width="120" prop="isStandardWeight" required :borderBottom="true">
					<up-radio-group v-model="orderSub.isStandardWeight" shape="square" :disabled="orderSub.disabled">
						<up-radio v-for="(item, index) in standardWeightList" :key="item" :name="item" :label="item"
							activeColor="green"></up-radio>
					</up-radio-group>
				</up-form-item>
				<up-form-item label="最小规格/kg" label-width="120" prop="minimum" required :borderBottom="true">
					<up-input placeholder="请输入最小规格" type="number" class="form-field-select" clearable
						v-model="orderSub.minimum" border="none" readonly :disabled="orderSub.disabled" />
				</up-form-item>
				<up-form-item label="箱规" label-width="120" prop="weight" required :borderBottom="true">
					<up-input placeholder="请输入箱规" type="number" class="form-field-select" clearable
						v-model="orderSub.weight" border="none" readonly :disabled="orderSub.disabled" />
				</up-form-item>
				<up-form-item label="外包装订单数量" label-width="120" prop="piece" required :borderBottom="true">
					<up-input placeholder="请输入盒/袋箱/件" type="number" class="form-field-select" clearable
						v-model="orderSub.piece" border="none" @update:modelValue="getWeightTotal()"
						:disabled="orderSub.disabled" />
				</up-form-item>
				<up-form-item label="销售单价（最小规格/元）" label-width="120" prop="price" required :borderBottom="true">
					<up-input placeholder="请输入销售单价" type="number" class="form-field-select" clearable
						v-model="orderSub.price" border="none" @update:modelValue="getWeightTotal()"
						:disabled="orderSub.disabled" />
				</up-form-item>
				<up-form-item label="销售合计/元" label-width="120" prop="priceTotal" required :borderBottom="true">
					<up-input placeholder="自动计算" type="number" class="form-field-select" v-model="orderSub.priceTotal"
						border="none" readonly :disabled="orderSub.disabled" />
				</up-form-item>
				<up-form-item label="订单重量/kg" label-width="120" prop="weightTotal" required :borderBottom="true">
					<up-input placeholder="自动计算" type="number" class="form-field-select" v-model="orderSub.weightTotal"
						border="none" readonly :disabled="orderSub.disabled" />
				</up-form-item>
				<up-form-item label="单价/公斤/元" label-width="120" prop="desc" required :borderBottom="true">
					<up-input placeholder="自动计算" type="number" class="form-field-select" v-model="orderSub.desc"
						border="none" readonly :disabled="orderSub.disabled" />
				</up-form-item>
				<up-form-item label="出库类型" label-width="120" prop="type" required :borderBottom="true">
					<up-radio-group v-model="orderSub.type" shape="square" :disabled="orderSub.disabled">
						<up-radio v-for="(item, index) in typeList" :key="item" :name="item" :label="item"
							activeColor="green"></up-radio>
					</up-radio-group>
				</up-form-item>
				<up-form-item label="是否分级" label-width="120" prop="isGraded" required :borderBottom="true">
					<up-radio-group v-model="orderSub.isGraded" shape="square" :disabled="orderSub.disabled">
						<up-radio v-for="(item, index) in gradedList" :key="item" :name="item" :label="item"
							activeColor="green"></up-radio>
					</up-radio-group>
				</up-form-item>
				<!-- #ifdef APP-->
				<up-form-item label="关联订单" label-width="110" prop="relatedString" :borderBottom="true"
					@tap="orderNumClick">
					<up-input placeholder="请选择关联订单" type="text" class="form-field-select"
						v-model="orderSub.relatedString" border="none" readonly :disabled="orderSub.disabled" />
				</up-form-item>
				<!-- #endif -->
				<!-- #ifdef H5-->
				<up-form-item label="关联订单" label-width="110" prop="relatedString" :borderBottom="true">
					<u-textarea placeholder="请选择关联订单" type="text" class="form-field-select" height="50"
						@click.native="orderNumShow=true" v-model="orderSub.relatedString" border="none" @focus='blur'
						:disabled="orderSub.disabled" />
				</up-form-item>
				<!-- #endif -->
				<up-form-item label="新旧货" label-width="120" prop="extent" required :borderBottom="true">
					<up-radio-group v-model="orderSub.extent" shape="square" :disabled="orderSub.disabled">
						<up-radio v-for="(item, index) in extentList" :key="index" :name="item" :label="item"
							activeColor="green"></up-radio>
					</up-radio-group>
				</up-form-item>
				<up-form-item label="打托方式(箱/托)" label-width="120" prop="palletizingMethod" required
					:borderBottom="true">
					<up-input placeholder="请输入打托方式" type="number" class="form-field-select"
						v-model="orderSub.palletizingMethod" border="none" :disabled="orderSub.disabled" />
				</up-form-item>
				<!-- #ifdef APP-->
				<up-form-item label="指定园区" label-width="120" prop="companyName" :borderBottom="true"
					@tap="parkShowClick">
					<up-input placeholder="请选择指定园区" type="text" class="form-field-select" v-model="orderSub.companyName"
						border="none" readonly :disabled="orderSub.disabled" />
				</up-form-item>
				<!-- #endif -->
				<!-- #ifdef H5-->
				<up-form-item label="指定园区" label-width="120" prop="companyName" :borderBottom="true">
					<up-input placeholder="请选择指定园区" type="text" class="form-field-select" v-model="orderSub.companyName"
						border="none" @click.native="parkShow=true" @focus='blur' :disabled="orderSub.disabled" />
				</up-form-item>
				<!-- #endif -->
				<up-form-item label="备注" label-width="110" prop="notes" :borderBottom="true">
					<up-textarea placeholder="请输入备注" type="text" class="form-field-select" v-model="orderSub.notes"
						border="none" :disabled="orderSub.disabled" />
				</up-form-item>
				<up-line color="#00aa00" dashed></up-line>
				<view style="display: flex;margin-top:1%;margin-bottom:1%;">
					<up-button type="primary" shape="circle" size="small" hairline plain text="新增子单"
						icon="plus-circle-fill" @click="addOrderSub"
						style="margin-left: 2%;margin-right: 2%;"></up-button>
					<!-- 	<u-button type="primary" shape="circle" size="small" hairline plain text="复制子单" icon="file-text"  @click="copyOrderSub"
						style="margin-right: 2%;"></u-button> -->
					<up-button color="#ff0000" shape="circle" size="small" hairline plain text="删除子单" icon="trash"
						@click="delOrderSub(orderSubCurrent)" style="margin-right: 2%;"
						:disabled="orderSub.disabled"></up-button>
				</view>
			</up-form>
			<view v-if="currentPage==2" class="settlement">
				<u-divider text="客户信息" :dashed="false" textColor="green" lineColor="green"></u-divider>
				<u-cell-group style="margin: 0px 15px 0px 15px;">
					<u-cell title="下单日期" :value="form.orderDate"></u-cell>
					<u-cell title="发货日期" :value="form.pickDate"></u-cell>
					<u-cell title="部门" :value="form.department"></u-cell>
					<u-cell title="客户名称" :value="form.customerName"></u-cell>
					<u-cell title="收货人" :value="form.customerTake"></u-cell>
					<u-cell title="收货人电话" :value="form.customerPhone"></u-cell>
					<u-cell title="收货人地址" :value="form.customerAddress"></u-cell>
				</u-cell-group>
				<u-divider text="订单信息" :dashed="false" textColor="green" lineColor="green"></u-divider>
				<u-cell-group style="margin: 0px 15px 0px 15px;">
					<u-cell :title="item.productName+'['+orderSubLetter[index]+']'" :value="item.skuName+'|'+item.packageMethod+'|'+
						nullConvert(item.innerPackageMethod)+'|'+item.varietyList.join(',')+'|'+item.grade"
						:label="'单价:'+item.price+' 重量:'+item.weightTotal+' 合计:'+item.priceTotal"
						v-for="(item,index) in orderList"></u-cell>
					<u-cell title="销售总价" :value="orderList.reduce((sum, item) => sum + Number(item.priceTotal), 0)"
						label="元"></u-cell>
				</u-cell-group>
				<u-divider text="已经到底啦" :dashed="false" textColor="green" lineColor="green"></u-divider>
			</view>
		</view>
		<view style="display: flex;">
			<u-button type="primary" :color="currentPage == 0 ? '#98999a':'green'" shape="circle" text="上一步"
				style="margin: 0px 5px 10px 10px;" :disabled="currentPage == 0" @click="lastPage"></u-button>
			<u-button type="primary" color="green" shape="circle" text="下一步" style="margin: 0px 10px 10px 5px;"
				@click="nextPage" v-if='currentPage!=2'></u-button>
			<u-button type="primary" color="green" shape="circle" text="生成订单" style="margin: 0px 10px 10px 5px;"
				@click="createOrderApi" v-if='currentPage==2 && form.id == null'></u-button>
			<u-button type="primary" color="green" shape="circle" text="补单保存" style="margin: 0px 10px 10px 5px;"
				@click="createOrderApi" v-if='currentPage==2 && form.id != null'></u-button>
		</view>

		<!-- 下单日期 -->
		<u-calendar :show="orderDateShow" mode="single" @confirm="orderDateChange" @close="orderDateShow=false"
			:minDate="minDate" :maxDate="maxDate" :monthNum="12"></u-calendar>

		<!-- 发货日期 -->
		<u-calendar :show="pickDateShow" mode="single" @confirm="pickDateChange" @close="pickDateShow=false"
			:minDate="minDate" :maxDate="maxDate" :monthNum="12"></u-calendar>

		<!-- 部门联动 -->
		<u-picker :show="departmentShow" :columns="departmentColumns" keyName="departmentName"
			@confirm="departmentConfirm" @close="departmentClose" @cancel="departmentClose"
			closeOnClickOverlay></u-picker>

		<!-- 客户联动 -->
		<!-- 		<u-picker :show="customerShow" :columns="customerColumns" @confirm="customerConfirm" @close="customerClose"
			@cancel="customerClose" closeOnClickOverlay></u-picker> -->
		<lzcPicker ref="lzcPicker" @change="customerConfirm" :pickerList="customerColumns"
			pickerTittle='选择客户(点击客户姓名即可)' />

		<!-- 省市区 -->
		<cityPicker :column="cityColumn" :default-value="cityDefaultValue" @cancel="cityCancel" @confirm="cityConfirm"
			:visible="cityShow" />

		<!-- 产品联动 -->
		<u-picker :show="productShow" :columns="productList" keyName="productName" @confirm="productConfirm"
			@close="productClose" @cancel="productClose" closeOnClickOverlay></u-picker>

		<!-- sku -->
		<u-picker :show="orderSub.params.skuShow" :columns="orderSub.params.skuList" keyName="sku" @confirm="skuConfirm"
			@close="skuClose" @cancel="skuClose" closeOnClickOverlay></u-picker>

		<!-- 关联订单 -->
		<multiple-picker title="请选择(近一个月订单)" :show="orderNumShow" :columns="orderNumList" :defaultIndex="orderNumIndex"
			@confirm="confirmOrderNum" @cancel="orderNumShow = false" @change="changeOrderNum"></multiple-picker>

		<!-- 指定园区 -->
		<u-picker :show="parkShow" :columns="parkList" keyName="company_name" @confirm="parkConfirm" @close="parkClose"
			@cancel="parkClose" closeOnClickOverlay></u-picker>

		<!-- 消息提示	 -->
		<u-toast ref="uToast" />

		<!-- 模态窗口 -->
		<u-modal :show="modal.show" :showConfirmButton='false'>
			<view class="slot-content">
				<rich-text :nodes="modal.content" style="font-weight: 400;"></rich-text>
			</view>
		</u-modal>
	</view>
</template>

<script>
	import departmentApi from '@/apis/gyl/department.js';
	import customerApi from '@/apis/gyl/customer.js';
	import baseApi from '@/apis/gyl/base.js';
	import productApi from '@/apis/gyl/product.js';
	import skuApi from '@/apis/gyl/sku.js';
	import orderApi from '@/apis/gyl/order.js';
	import cityPicker from '@/uni_modules/piaoyi-cityPicker/components/piaoyi-cityPicker/piaoyi-cityPicker';
	import lzcPicker from '@/components/lzc-picker/lzc-picker.vue';
	import multiplePicker from '@/components/multiple-picker/multiple-picker.vue';
	import {
		onPageScroll
	} from '@dcloudio/uni-app';
	import {
		ref,
		reactive
	} from 'vue';
	export default {
		components: {
			cityPicker,
			lzcPicker,
			multiplePicker
		},
		data() {
			return {
				// scrollTop: 0,
				saleId:null,
				tabList: [{
					name: '子单[A]'
				}],
				parkName: null,
				currentPage: 0,
				action: "",
				fileList: [],
				minDate: '2024-12-01',
				maxDate: '2035-01-01',
				saleTypeList: ['销售', '样品'],
				choiceCarList: ['供应链车辆', '客户自提', '快递'],
				departmentShow: false, //控制部门展示
				departmentColumns: [], //部门列表
				customerShow: false, //控制客户展示
				customerList: [], //源客户列表
				customerColumns: [], //客户列表
				cityShow: false,
				cityDefaultValue: '',
				cityColumn: 3,
				accountPeriodList: ['发货前付款', '货到付款', '账期7天', '账期15天', '账期30天'],
				areList: [],
				customerPayList: ['对公账户', '个人扫码', '转账'],
				isUnloadingList: [{
					value: 1,
					name: "是"
				}, {
					value: 0,
					name: "否"
				}],
				isInvoicingList: [{
					value: 1,
					name: "是"
				}, {
					value: 0,
					name: "否"
				}],
				isUrgentList: [{
					value: 1,
					name: "是"
				}, {
					value: 0,
					name: "否"
				}],
				fileList1: [],
				fileList2: [],
				orderDateShow: false,
				pickDateShow: false,
				labelStyle: {
					color: '#646566',
					fontSize: '30rpx'
				},
				form: {
					id: null,
					orderDate: null,
					sample: null,
					choiceCar: null,
					pickDate: null,
					department: null,
					customerName: null,
					accountPeriod: null,
					salesPerson: null,
					area: null,
					customerId: null,
					customerTake: null,
					customerPhone: null,
					pcaAddress: null,
					textProvince: null,
					textCity: null,
					textArea: null,
					customerAddress: null,
					customerForm: null,
					customerPay: null,
					customerAccount: null,
					isUnloading: 0,
					unloadingDays: null,
					unloadingFare: null,
					isInvoicing: 0,
					isUrgent: 0,
					remake: null,
					orderImage: null, //相关图片
					orderText: null, //相关文件
				},
				standardWeightList: ['标重', '非标重'],
				extentList: ['新货(库存四天内)', '旧货(库存四天以上)'],
				typeList: ['销售', '赠品', '样品'],
				gradedList: ['分级出库', '通货出库'],
				parkList: [],
				parkShow: false,
				productList: [],
				productShow: false,
				orderNumList: [],
				orderNumShow: false,
				orderNumIndex: [],
				orderList: [], //子单集合
				orderSubCurrent: 0,
				orderSubLetter: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
					'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
				],
				orderSub: {
					skuName: null,
					packageMethod: null,
					innerPackageMethod: null,
					productName: null,
					varietyList: [],
					varietyName: null,
					grade: null,
					minimum: null,
					weight: null,
					piece: null,
					price: null,
					priceTotal: null,
					weightTotal: null,
					desc: null,
					type: null,
					isGraded: null,
					isStandardWeight: null,
					relatedString: null,
					relatedList: [],
					extent: null,
					palletizingMethod: null,
					companyName: null,
					newDbName: null,
					notes: null,
					params: {
						skuShow: false,
						skuList: [],
						productId: null,
						packageMethodList: [], //外包装
						innerPackageMethodList: [], //内包装
						varietyNameList: [], //品种
						gradeList: [], //等级
					}
				},
				customerRules: {
					orderDate: [{
						required: true,
						message: '请选择下单日期',
						trigger: ['blur', 'change']
					}],
					sample: [{
						required: true,
						message: '请选择销售类型',
						trigger: ['blur', 'change']
					}],
					choiceCar: [{
						required: true,
						message: '请选择发货方式',
						trigger: ['blur', 'change']
					}],
					pickDate: [{
						required: true,
						message: '请选择发货日期',
						trigger: ['blur', 'change']
					}],
					department: [{
						required: true,
						message: '请选择部门',
						trigger: ['blur', 'change']
					}],
					customerName: [{
						required: true,
						message: '请选择客户',
						trigger: ['blur', 'change']
					}],
					accountPeriod: [{
						required: true,
						message: '请选择付款账期',
						trigger: ['blur', 'change']
					}],
					salesPerson: [{
						required: true,
						message: '请填写销售人员',
						trigger: ['blur', 'change']
					}],
					area: [{
						required: true,
						message: '请选择所在区域',
						trigger: ['blur', 'change']
					}],
					customerTake: [{
						required: true,
						message: '请填写收货人',
						trigger: ['blur', 'change']
					}],
					customerPhone: [{
						required: true,
						message: '请填写收货人电话',
						trigger: ['blur', 'change']
					}],
					pcaAddress: [{
						required: true,
						message: '请填写收货人地址',
						trigger: ['blur', 'change']
					}],
					customerAddress: [{
						required: true,
						message: '请填写收货人详细地址',
						trigger: ['blur', 'change']
					}],
					customerForm: [{
						required: true,
						message: '请填写客户形式',
						trigger: ['blur', 'change']
					}],
					customerPay: [{
						required: true,
						message: '请选择付款方式',
						trigger: ['blur', 'change']
					}],
					customerAccount: [{
						required: true,
						message: '请填写客户付款账号',
						trigger: ['blur', 'change']
					}],
					unloadingDays: [{
						validator: (rule, value, callback) => {
							if (this.form.isUnloading == 0) {
								return true;
							}
							return this.form.isUnloading == 1 && this.form.unloadingDays != null;
						},
						required: true,
						message: '请填写押车天数',
						trigger: ['blur', 'change']
					}],
					unloadingFare: [{
						validator: (rule, value, callback) => {
							if (this.form.isUnloading == 0) {
								return true;
							}
							return this.form.isUnloading == 1 && this.form.unloadingFare != null;
						},
						required: true,
						message: '请填写预计押车费用',
						trigger: ['blur', 'change']
					}]
				},
				orderRules: {
					productName: [{
						required: true,
						message: '请选择产品',
						trigger: ['blur', 'change']
					}],
					skuName: [{
						required: true,
						message: '请选择SKU名称',
						trigger: ['blur', 'change']
					}],
					packageMethod: [{
						required: true,
						message: '请选择外包装',
						trigger: ['blur', 'change']
					}],
					// innerPackageMethod: [{
					// 	validator: (rule, value, callback) => {
					// 		if (this.orderSub.params.innerPackageMethodList.length == 0) {
					// 			return true;
					// 		}
					// 		return this.orderSub.params.innerPackageMethodList.length > 0 && this.orderSub
					// 			.innerPackageMethod != null;
					// 	},
					// 	required: true,
					// 	message: '请选择内包装',
					// 	trigger: ['blur', 'change']
					// }],
					varietyList: [{
						type: 'array',
						required: true,
						message: '请选择品种',
						trigger: ['blur', 'change']
					}],
					grade: [{
						required: true,
						message: '请选择等级',
						trigger: ['blur', 'change']
					}],
					minimum: [{
						required: true,
						message: '请输入最小规格',
						trigger: ['blur', 'change']
					}],
					weight: [{
						required: true,
						message: '请输入箱规',
						trigger: ['blur', 'change']
					}],
					piece: [{
						required: true,
						message: '请输入外包装订单数量',
						trigger: ['blur', 'change']
					}],
					price: [{
						required: true,
						message: '请输入销售单价',
						trigger: ['blur', 'change']
					}],
					priceTotal: [{
						required: true,
						message: '请输入销售合计',
						trigger: ['blur', 'change']
					}],
					weightTotal: [{
						required: true,
						message: '请输入订单重量',
						trigger: ['blur', 'change']
					}],
					desc: [{
						required: true,
						message: '请输入单价/公斤/元',
						trigger: ['blur', 'change']
					}],
					type: [{
						required: true,
						message: '请选择出库类型',
						trigger: ['blur', 'change']
					}],
					isGraded: [{
						required: true,
						message: '请选择是否分级',
						trigger: ['blur', 'change']
					}],
					isStandardWeight: [{
						required: true,
						message: '请选择是否标重',
						trigger: ['blur', 'change']
					}],
					extent: [{
						required: true,
						message: '请选择新旧货',
						trigger: ['blur', 'change']
					}],
					palletizingMethod: [{
						required: true,
						message: '请输入打托方式',
						trigger: ['blur', 'change']
					}],
				},
				modal: {
					show: false,
					title: '',
					content: ''
				}
			}
		},
		methods: {
			// -------------------------------------------------------------------------分割线  下面是app H5 兼容方法 -----------------------------------------------------------------------------------------			

			// #ifdef APP
			/**
			 * 用于app下展示下单日期校验规则,兼容键盘弹出的bug
			 */
			orderDateClick() {
				this.orderDateShow = true;
				this.$refs.orderForm.validateField('orderDate');
			},

			/**
			 * 用于app下展示发货日期校验规则,兼容键盘弹出的bug
			 */
			pickDateClick() {
				this.pickDateShow = true;
				this.$refs.orderForm.validateField('pickDate');
			},

			/**
			 * 用于app下展示部门校验规则,兼容键盘弹出的bug
			 */
			departmentClick() {
				this.departmentShow = true;
				this.$refs.orderForm.validateField('department');
			},

			/**
			 * 用于app下展示客户校验规则,兼容键盘弹出的bug
			 */
			customerClick() {
				this.customerShowClick(); //调用客户展示
				this.$refs.orderForm.validateField('customerName');
			},

			productNameClick() {
				this.productShow = true;
				// this.$refs.orderForm.validateField('customerName');
			},

			skuNameClick() {
				this.orderSub.params.skuShow = true;
				// this.$refs.orderForm.validateField('customerName');
			},

			orderNumClick() {
				this.orderNumShow = true;
				// this.$refs.orderForm.validateField('customerName');				
			},

			parkShowClick() {
				this.parkShow = true;
				// this.$refs.orderForm.validateField('customerName');						
			},
			// #endif  		

			// -------------------------------------------------------------------------分割线  下面是基本信息页面方法 ----------------------------------------------------------------------------------------- 				

			/**转换null
			 * @param {Object} object
			 */
			nullConvert(object) {
				console.info()
				return object == null ? '无' : object;
			},
			/**
			 * 做空判断
			 * @param {Object} object
			 */
			emptyJudgment(object) {
				return object == null || object == '';
			},

			/**
			 * 回到顶部
			 */
			scrollToTop() {
				uni.pageScrollTo({
					scrollTop: 0
				});
			},

			/**用于返回顶端的方法
			 * @param {Object} e
			 */
			// onPageScroll(e) {
			// 	this.scrollTop = e.scrollTop;
			// },

			/**
			 * 上一页的切换
			 */
			lastPage() {
				this.currentPage--;
				this.scrollToTop();
			},

			/**
			 * 下一页的切换
			 */
			async nextPage() {
				//这里做校验
				if (this.currentPage == 0) { //客户校验
					await this.$refs.orderForm.validate().then(res => {
						this.currentPage++;
					}).catch(errors => {
						uni.$u.toast(errors[0].message)
					})
					this.scrollToTop();
				} else if (this.currentPage == 1) { //订单校验
					var flag = false;
					var index = 0;
					for (var i = 0; i < this.orderList.length; i++) {
						const order = this.orderList[i];
						if (this.emptyJudgment(order.skuName) || this.emptyJudgment(order.packageMethod) ||
							this.emptyJudgment(order.productName) ||
							this.emptyJudgment(order.grade) || this.emptyJudgment(order.minimum) ||
							this.emptyJudgment(order.weight) || this.emptyJudgment(order.piece) ||
							this.emptyJudgment(order.price) || this.emptyJudgment(order.priceTotal) ||
							this.emptyJudgment(order.weightTotal) || this.emptyJudgment(order.desc) ||
							this.emptyJudgment(order.type) || this.emptyJudgment(order.isGraded) ||
							this.emptyJudgment(order.isStandardWeight) || this.emptyJudgment(order.extent) ||
							this.emptyJudgment(order.palletizingMethod)) {
							flag = true;
							index = i;
							break;
						}
						if (order.varietyList == null || order.varietyList.length == 0) {
							flag = true;
							index = i;
							break;
						}
						// if (order.params.innerPackageMethodList.length > 0 && (order.innerPackageMethod ==
						// 		null || order.innerPackageMethod == '')) {
						// 	flag = true;
						// 	index = i;
						// 	break;
						// }
					}
					console.info(flag)
					if (flag) {
						//如果有一个为true则代表校验没通过
						this.orderSubCurrent = index;
						this.orderSub = this.orderList[index];
						this.$refs.orderSubForm.validate().then(res => {}).catch(errors => {
							uni.$u.toast(errors[0].message)
						})
						this.scrollToTop();
					} else {
						this.currentPage++;
						this.scrollToTop();
					}
				}


			},

			/**
			 * 禁止弹出
			 */
			async blur() {
				await uni.hideKeyboard();
			},


			/**
			 * 下单日期
			 * @param {Object} e
			 */
			orderDateChange(e) {
				this.form.orderDate = e[0]
				this.orderDateShow = false;
				this.$refs.orderForm.validateField('orderDate')
			},

			/**
			 * 发货日期
			 * @param {Object} e
			 */
			pickDateChange(e) {
				this.form.pickDate = e[0]
				this.pickDateShow = false;
				this.$refs.orderForm.validateField('pickDate');
			},

			/**
			 * 部门确定
			 * @param {Object} e
			 */
			departmentConfirm(e) {
				console.info(e)
				this.form.department = e.value[0].departmentName; //获取选择的数据
				this.departmentShow = false;
				this.$refs.orderForm.validateField('department');
			},

			/**
			 * 部门取消
			 */
			departmentClose() {
				this.departmentShow = false;
			},

			/**
			 * 客户展示
			 */
			customerShowClick() {
				this.$refs.lzcPicker.handleShow();
			},

			/**
			 * 客户确定
			 * @param {Object} e
			 */
			customerConfirm(index) {
				this.customerShow = false;
				const customer = this.customerList[index];
				this.form.area = customer.department;
				this.form.customerId = customer.customerId;
				this.form.salesPerson = customer.salePerson;
				this.form.customerName = customer.customerName;
				this.form.customerTake = customer.customerTake;
				this.form.customerPhone = customer.customerPhone;
				this.form.customerAddress = customer.customerAddress;
				this.form.customerForm = customer.customerForm;
				this.form.customerPay = customer.customerPay;
				this.form.customerAccount = customer.customerAccount;
				this.form.accountPeriod = customer.accountPeriod;
				this.form.isInvoicing = customer.isInvoicing;
				this.form.textProvince = customer.textProvince;
				this.form.textCity = customer.textCity;
				this.form.textArea = customer.textArea;
				this.form.pcaAddress = customer.textProvince + "/" + customer.textCity + "/" + customer.textArea;
				this.$refs.orderForm.validateField('customerName');
				this.$refs.orderForm.validateField('accountPeriod');
				this.$refs.orderForm.validateField('area');
				this.$refs.orderForm.validateField('customerPay');
			},

			/**
			 * 客户取消
			 */
			customerClose() {
				this.customerShow = false;
			},

			/**
			 * 省市区取消
			 */
			cityCancel() {
				this.cityShow = false;
			},

			/**省市区确认
			 * @param {Object} e
			 */
			cityConfirm(e) {
				this.form.textProvince = e.provinceName;
				this.form.textCity = e.cityName;
				this.form.textArea = e.areaName;
				this.form.pcaAddress = e.provinceName + "/" + e.cityName + "/" + e.areaName;
				this.cityCancel();
			},

			/**
			 * 新增图片
			 */
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},

			/**删除图片
			 * @param {Object} event
			 */
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},

			/**上传图片到服务器
			 * @param {Object} url
			 */
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://121.229.107.81:81/api/file/salesOrderFileUpload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},

			// -------------------------------------------------------------------------分割线  下面是销售订单页面的方法 -----------------------------------

			/**
			 * tab页切换
			 * @param {Object} item
			 */
			tabsClick(item) {
				const index = item.index; //获取下标
				this.orderSubCurrent = index; //赋值到当前子单页下标
				if (this.orderList.length < index + 1) {
					this.orderSub = this.getSourceOrder();
					this.orderList.push(this.orderSub);
				} else {
					this.orderSub = this.orderList[index];
					this.$refs.orderSubForm.validate().then(res => {}).catch(errors => {
						uni.$u.toast(errors[0].message)
					})
				}
			},

			/**
			 * 产品关闭
			 */
			productClose() {
				this.productShow = false;
			},

			/**产品确认
			 * @param {Object} e
			 */
			productConfirm(e) {
				if (this.orderSub.productName != e.value[0].productName) { //清空选项
					this.orderSub.params.packageMethodList = [];
					this.orderSub.params.innerPackageMethodList = [];
					this.orderSub.params.varietyNameList = [];
					this.orderSub.params.gradeList = [];
					this.orderSub.packageMethod = null;
					this.orderSub.innerPackageMethod = null;
					this.orderSub.varietyList = [];
					this.orderSub.grade = null;
					this.orderSub.skuName = null;
				}
				this.orderSub.params.productId = e.value[0].id;
				this.orderSub.productName = e.value[0].productName;
				this.tabList[this.orderSubCurrent].name = e.value[0].productName + '[' + this.orderSubLetter[this
					.orderSubCurrent] + ']';
				this.productClose();
				const id = e.value[0].id; //获取catId
				const selectArr = this.departmentColumns[0].filter(item => item.departmentName == this.form.department);
				console.info(selectArr)
				if (selectArr[0].id == 3 || selectArr[0].id == 4 || selectArr[0].id == 6) {
					this.getSkuByProductApi({
						pageNum: 1,
						pageSize: 100,
						catId: id,
						departmentId: selectArr[0].id
					})
				} else {
					this.getSkuByProductApi({
						pageNum: 1,
						pageSize: 100,
						catId: id
					})
				}

			},

			/**
			 * sku关闭
			 */
			skuClose() {
				this.orderSub.params.skuShow = false;
			},

			/**sku确认
			 * @param {Object} e
			 */
			skuConfirm(e) {
				if (this.orderSub.skuName != e.value[0].sku) { //清空选项
					this.orderSub.params.packageMethodList = [];
					this.orderSub.params.innerPackageMethodList = [];
					this.orderSub.params.varietyNameList = [];
					this.orderSub.params.gradeList = [];
					this.orderSub.packageMethod = null;
					this.orderSub.innerPackageMethod = null;
					this.orderSub.varietyList = [];
					this.orderSub.grade = null;
				}
				this.orderSub.skuName = e.value[0].sku;
				this.orderSub.minimum = e.value[0].miniNum;
				this.orderSub.weight = e.value[0].boxGauge;
				this.skuClose();
				this.orderSub.params.packageMethodList = e.value[0].outerPackageList;
				this.orderSub.params.innerPackageMethodList = e.value[0].innerPackageList;
				const result = e.value[0].skuProductList.filter(item => item.productId === this.orderSub.params.productId);
				this.orderSub.params.varietyNameList = result[0].variety.split(',');
				this.orderSub.params.gradeList = result[0].grade.split(',');
			},

			/**
			 * 自动计算价格数据
			 */
			getWeightTotal() {
				console.info(this.orderSub.weight, this.orderSub.piece, this.orderSub.price, this.orderSub.minimum);
				this.orderSub.priceTotal = (this.orderSub.weight * this.orderSub.piece * this.orderSub.price).toFixed(
				2); //销售合计
				this.orderSub.weightTotal = (this.orderSub.minimum * this.orderSub.weight * this.orderSub.piece).toFixed(
				2); //订单重量
				this.orderSub.desc = (this.orderSub.price / this.orderSub.minimum).toFixed(2); //单价每公斤
				console.info(this.orderSub)
			},

			/**
			 * 指定园区取消
			 */
			parkClose() {
				this.parkShow = false;
			},

			/**指定园区确认
			 * @param {Object} e
			 */
			parkConfirm(e) {
				console.info(e)
				this.orderSub.companyName = e.value[0].company_name;
				this.orderSub.newDbName = e.value[0].new_db_name;
				this.parkClose();
			},

			/**
			 * 新增子单
			 */
			addOrderSub() {
				this.tabList.push({
					name: "子单" + '[' + this.orderSubLetter[this.tabList.length] + ']'
				})
				this.orderSub = this.getSourceOrder();
				this.orderList.push(this.orderSub);
				this.orderSubCurrent = this.tabList.length - 1;
				this.scrollToTop();
			},

			/**
			 * 复制子单
			 */
			copyOrderSub() {

			},

			/**
			 * 删除子单
			 */
			delOrderSub(index) {
				this.tabList.splice(index, 1);
				this.orderList.splice(index, 1);
				this.orderSubCurrent = 0;
				this.orderSub = this.orderList[0];
				this.scrollToTop();
				this.tabList.forEach((item, index) => {
					item.name = item.name.substring(0, item.name.length - 3) + '[' + this.orderSubLetter[index] +
						']';
				})
			},

			/**
			 * 获取源订单信息
			 */
			getSourceOrder() {
				var arr = this.parkList[0].filter(
					(item) => item.company_name.indexOf(this.parkName) != -1
				);
				this.parkList = [];
				this.parkList.push(arr);
				return {
					skuName: null,
					packageMethod: null,
					innerPackageMethod: null,
					productName: null,
					varietyName: null,
					varietyList: [],
					grade: null,
					minimum: null,
					weight: null,
					piece: null,
					price: null,
					priceTotal: null,
					weightTotal: null,
					desc: null,
					type: null,
					isGraded: null,
					isStandardWeight: null,
					relatedString: null,
					relatedList: [],
					extent: null,
					palletizingMethod: null,
					companyName: this.parkList[0][0].company_name,
					newDbName: this.parkList[0][0].new_db_name,
					notes: null,
					params: {
						skuShow: false,
						skuList: [],
						productId: null,
						packageMethodList: [], //外包装
						innerPackageMethodList: [], //内包装
						varietyNameList: [], //品种
						gradeList: [], //等级
					},
					disabled: false
				}
			},

			/**关联订单勾选时触发
			 * @param {Object} e
			 */
			changeOrderNum(e) {
				// console.log(e);	
			},

			/**关联订单确认时触发
			 * @param {Object} e
			 */
			confirmOrderNum(e) {
				if (e.selected) {
					var arr = e.selected.map(item => item.label);
					console.info(arr)
					this.orderSub.relatedString = arr.join(",");
					this.orderSub.relatedList = e.selected.map(item => item.value);
				}
				this.orderNumShow = false;
			},
			// /**
			//  * 展示
			//  */
			// showLoadingToast() {
			// 	this.$refs.uToast.show({
			// 		type: 'loading', // 设置toast类型为加载中
			// 		message: '提交订单中请稍后...', // 提示文字
			// 		duration: 10000, // 持续时间设为0表示不会自动关闭
			// 	});
			// },

			// /**
			//  * 关闭提示
			//  */
			// hideToast() {
			// 	console.info(this.$refs.uToast)
			// 	this.$refs.uToast.hide(); // 关闭toast
			// },
			// -------------------------------------------------------------------------分割线  下面是接口 --------------------------------------------------------------------------

			/**
			 * 获取部门数据
			 */
			async getDepartmentListApi() {
				const res = await departmentApi.listNoTree();
				if (res.success) {
					const list = res.data;
					// const departmentColumns = list.map(item => item.departmentName);
					this.departmentColumns.push(list);
				}
			},

			/**
			 * 获取客户列表
			 */
			async getCustomerListApi() {
				var query = {
					pageNo: 1,
					pageSize: 1000
				};
				const res = await customerApi.listCustomer(query);
				if (res.success) {
					const list = res.data;
					this.customerList = res.data;
					const customerList = list.map((item, index) => ({
						customerName: item.customerName,
						index: index
					}));
					// this.customerColumns.push(customerList);
					this.customerColumns = customerList;
				}
			},

			/**
			 * 获取所在区域
			 */
			async getAreaListApi() {
				const res = await baseApi.listArea();
				if (res.success) {
					this.areList = res.data.map(item => item.regionName);
				}
			},

			/**
			 * 获取所有园区
			 */
			async getYQListPHPApi() {
				this.parkList = [];
				uni.request({
					url: 'http://121.229.177.46:82/index.php/User/UserInfo/get_yq_list3',
					success: res => {
						this.parkList.push(res.data.data);
					}
				})
			},

			/**
			 * 获取所有产品集合
			 */
			async getProductListApi() {
				const res = await productApi.listProduct();
				this.productList = [];
				if (res.success) {
					this.productList.push(res.data.records);
				}
			},

			/**根据产品获取对应的sku集合
			 * @param {Object} query
			 */
			async getSkuByProductApi(query) {
				const res = await skuApi.listProduct(query);
				this.orderSub.params.skuList = [];
				if (res.success) {
					this.orderSub.params.skuList.push(res.data.records)
				}
			},

			/**
			 * 关联订单
			 */
			async getRelatedOrderListApi() {
				const res = await orderApi.listRelatedOrder()
				this.orderNumList = [];
				if (res.success) {
					this.orderNumList = res.data;
				}
			},

			/**
			 * 生成订单
			 */
			async createOrderApi() {
				// this.modal.show = true;
				// this.modal.content = '正在提交订单，请稍后......';
				for (var i = 0; i < this.orderList.length; i++) {
					var order = this.orderList[i];
					if (order.varietyList && order.varietyList.length > 0) {
						order.varietyName = order.varietyList.join(",");
					} else {
						order.varietyName = '';
					}
				}
				this.$refs.uToast.show({
					type: 'loading',
					message: '提交订单中',
					duration: 100000, // 设置适当的持续时间
					complete: () => {
						// 执行完成后的逻辑，例如页面跳转或其他操作
						console.log('操作成功');
						// this.navigateToNextPage();
					}
				});
				this.orderList = this.orderList.filter(item=>!item.disabled);
				const res = await orderApi.repairOrder({
					sellId: this.form.id,
					saleId: this.saleId,
					list: this.orderList
				});
				if (res.success) {
					var obj = this;
					obj.$refs.uToast.show({
						type: 'success',
						message: '订单补单成功',
						duration: 1000, // 设置适当的持续时间
						complete: () => {
							uni.redirectTo({
								url: '/pages/supplyChain/sellHome/index'
							});
						}
					});
				} else {
					// this.modal.show = false;
					uni.$u.toast("补单订单失败");
				}
			},

			/**
			 * 根据id获取订单
			 * @param {Object} id
			 */
			async getOrderApi(id) {
				uni.setNavigationBarTitle({
					title: "订单补单"
				});
				const res = await orderApi.getBySaleId(id);
				if (res.success) {
					await this.getDepartmentListApi();
					await this.getProductListApi();
					this.form = res.data.info;
					// this.form.id = id;
					this.orderList = res.data.orderList;
					this.orderSub = this.orderList[0];
					this.form.pcaAddress = this.form.textProvince + "/" + this.form.textCity + "/" + this.form
						.textArea;
					this.tabList = [];
					this.parkName = res.data.saleList[0].companyName;
					for (var i = 0; i < this.orderList.length; i++) {
						var order = this.orderList[i];
						this.$set(order, 'disabled', true);
						var tab = {};
						tab.name = order.productName + '[' + this.orderSubLetter[i] + ']';
						this.tabList.push(tab);
						this.$set(order, 'params', {
							skuShow: false,
							skuList: [],
							productId: null,
							packageMethodList: [], //外包装
							innerPackageMethodList: [], //内包装
							varietyNameList: [], //品种
							gradeList: [], //等级
						})
						const selectArr = this.departmentColumns[0].filter(item => item.departmentName == this.form
							.department);
						//先筛选产品 产品id关联着sku
						const productList = this.productList[0].filter(item => item.productName == order.productName);
						//筛选sku
						var query = {};
						if (selectArr[0].id == 3 || selectArr[0].id == 4 || selectArr[0].id == 6) {
							query = {
								pageNum: 1,
								pageSize: 100,
								catId: productList[0].id,
								departmentId: selectArr[0].id
							}
						} else {
							query = {
								pageNum: 1,
								pageSize: 100,
								catId: productList[0].id,
							}
						}
						const skuRes = await skuApi.listProduct(query);
						order.params.skuList = [];
						order.params.skuList.push(skuRes.data.records)
						order.params.productId = productList[0].id;
						const skuList = skuRes.data.records.filter(item => item.sku == order.skuName);
						const sku = skuList[0].skuProductList.filter(item => item.productId == order.params.productId);
						order.params.packageMethodList = skuList[0].outerPackageList;
						order.params.innerPackageMethodList = skuList[0].innerPackageList;
						order.params.varietyNameList = sku[0].variety.split(',');
						order.params.gradeList = sku[0].grade.split(',');
						order.varietyList = order.varietyName.split(",");

						console.info(order)
					}


				}
			}
		},
		onLoad(option) {
			// uni.setStorageSync("orderToken",
			// 	"eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE3MzUyODc4MjMsInN1YiI6Im1mLmdhbmdrZSIsImlhdCI6MTczNTI4MDYyMzQ0M30.-S4vusRrwS3gIbAnJvg1lAi7GPIOZPAVu1oJ89U4hGXt_uBanVf3Opz7G8eZESz1wlt62pG7adX2QRXIrhki5A"
			// )
			// this.getDepartmentListApi();
			this.getCustomerListApi();
			this.getAreaListApi();
			this.getYQListPHPApi();
			// this.getProductListApi();
			this.getRelatedOrderListApi();
			if (option.id) { //补单
			    this.saleId = option.id;
				this.getOrderApi(option.id);
			} else { //新增
				this.getDepartmentListApi();
				this.getProductListApi();
				this.orderList.push(this.orderSub);
			}

		},
		onReady() {
			this.$refs.orderForm.setRules(this.customerRules);
			this.$refs.orderSubForm.setRules(this.orderRules);
		},
		setup() {
			// 使用 ref 创建响应式基本类型数据  
			const scrollTop = ref(0);
			// onPageScroll 方法来更新 scrollTop 的值  
			onPageScroll((e) => {
				scrollTop.value = e.scrollTop;
			});
			// tabList: [{
			// 	name: '子单[A]'
			// }],
			// const tabList = reactive([{
			// 	name: '子单[A]'
			// }])
			return {
				scrollTop,
				onPageScroll
			}
		}
	}
</script>

<style lang="scss" scoped>
	.apply-form-field {
		background: #ffffff;

		.u-form-item {
			padding: 0px 15px !important;
		}

		.input-placeholder {
			text-align: left !important;
			font-size: 28rpx;
		}

		.uni-input-input {
			text-align: left !important;
		}

		.form-field-select {
			.u-iconfont {
				font-size: 0 !important;
			}
		}

		.add-user {
			color: #bfbfbf;
			font-size: 30px;
		}

		.apply-name {
			color: #333333;
			line-height: 20px;

			span {
				color: #999999;
				display: block;

			}
		}

		.apply-link {
			.u-link {
				color: #5ab149 !important;
				padding: 0 5px;
			}
		}

		.u-close--top-right {
			top: 5px !important;
		}

		.popup-title {
			color: #333333;
			padding: 5px 10px;
			font-size: 30rpx;
		}

		.u-cell {
			padding: 8px 12px !important;
		}
	}

	.u-radio-group--row {
		flex-wrap: wrap;
	}

	.u-radio {
		margin-right: 8px !important;
		// margin-bottom: 5px;
		// padding: 1px;
	}

	.u-radio-group {
		gap: 0px !important;
	}

	.u-form {
		background-color: #fff;
		border-left: 2px solid #f0f0f1;
		border-top: 2px solid #f0f0f1;
		border-right: 1px solid #bcbcbd;
		border-bottom: 1px solid #bcbcbd;
		box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);
		border-radius: 15px;
	}

	.settlement {
		background-color: #fff;
		border-left: 2px solid #f0f0f1;
		border-top: 2px solid #f0f0f1;
		border-right: 1px solid #bcbcbd;
		border-bottom: 1px solid #bcbcbd;
		box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);
		border-radius: 15px;
		// padding: 10px;
	}

	.u-sticky {
		border-bottom: 1px solid #d7d9da;
		box-shadow: 5px 5px 12px rgba(0, 0, 0, 0.3);
	}

	.u-tabs {
		border-radius: 15px !important;
	}

	::v-deep .u-cell__value {
		text-align: left !important;
		width: 60% !important;
	}
</style>